package com.situ.web.service;

import java.util.List;

import com.situ.web.Dao.TeacherDao;
import com.situ.web.entity.PageInfo;
import com.situ.web.entity.Student;
import com.situ.web.entity.Teacher;

public class TeacherService {
	private TeacherDao teacherDao = new TeacherDao();
	

	public PageInfo findByPage(int pageNo, int pageSize) {
		PageInfo pageInfo = new PageInfo();
		//第几页
		pageInfo.setPageNo(pageNo);
		//每页几条数据
		pageInfo.setPageSize(pageSize);
		//共有多少页
		//一个Dao中计算多少数据的方法
		int totalCount = teacherDao.getTotalCount();
		int totalPage = (int) Math.ceil((double)totalCount / pageSize);
		pageInfo.setTotalPage(totalPage);
		//存放这一页的数据：LIst
		int offset = (pageNo - 1) * pageSize;
		//把得到的数据offset，pageSize，传到Dao，创建方法findByPage;
		//返回的是pageInfo；
		List<Teacher> list = teacherDao.findByPage(offset,pageSize);
		pageInfo.setList(list);
		return pageInfo;
	}


	public List<Teacher> findAll() {
		List<Teacher> list = teacherDao.findAll();
		return list;
	}


	public boolean deleteById(int id) {
		//dao层返回影响的行数
		int count = teacherDao.deleteById(id);
		if (count == 1) {
			return true;
		} else {
			return false;
		}
		
		
	}


	public boolean insert(Teacher teacher) {
		int count = teacherDao.insert(teacher);
		if (count == 1) {
			return true;
		} else {
			return false;
		}
	}


	public Teacher selectById(int id) {
		Teacher teacher = teacherDao.selectById(id);
		return teacher;
	}


	public boolean update(Teacher teacher) {
		int count = teacherDao.update(teacher);
		if (count == 1) {
			return true;
		} else {
			return false;
		}
	}

}
